<?php
class UtilController extends Controller{
	
	public function actionPass(){
		$password = 'loveyou';
		$pass = md5($password);
        file_put_contents('qxh.txt',$pass);
	}

    public function actionTest(){
        echo 999;exit;
        md5('123');
	}
	
	public function actionHandleKeywords(){
        //The keywords are store in keywords.log temporarily
        //This action can restore all the keywords to db
		$lines = FileUtil::getAllKeywords();
		$cnt = count($lines);
        BookService::handleKeywords($lines);
        echo $cnt;
	}

    public function actionHandleBookIds(){
        //The bookids clicked are store in bookids.log temporarily
        //This action can restore all the bookids to db
		$bookIdArr = FileUtil::getAllBookIds();
		$cnt = count($bookIdArr);
		BookService::increClickedTimes($bookIdArr);
		echo $cnt;
	}
	
	public function actionClearAllCache(){
		Yii::app()->smarty->clear_all_cache();
		echo 0;
	}
	
	public function actionClearHomeCache(){
		Yii::app()->smarty->clear_cache('index.tpl');
		echo 0;
	}
	
	public function actionClearClassCache(){
		$cidAndPageno = Param::getStr('cid_pageno');
		Yii::app()->smarty->clear_cache('book/clist.tpl','bookclass_'.$cidAndPageno);
		echo 0;
	}
	
	public function actionClearViewCache(){
		$id = Param::getStr('id');
		Yii::app()->smarty->clear_cache('book/view.tpl','book_'.$id);
		echo 0;
	}

    public function actionSearchTongji(){
        $dayStr = $_GET['day'];
        $year = substr($dayStr,0,4);
        $month = intval(substr($dayStr,4,2));
        $day = intval(substr($dayStr,6,2));

        $dayBegin = mktime(0,0,0,$month,$day,$year);
        $dayEnd = mktime(23,59,59,$month,$day,$year);

        $sql = "SELECT count(*) FROM `ccs8_search` WHERE ctime > $dayBegin and ctime < $dayEnd";

        $cnt = DBUtil::queryScalar($sql);
        echo "click times in $dayStr is $cnt";
    }

    public function actionSetOK(){
        $sql = 'update ccs8_book set book_status=1';
        DBUtil::exec($sql);
        echo 0;
    }

    public function actionNotOK(){
        header("Content-type:text/html;charset=utf-8");
        $sql = "select * from ccs8_book where book_status=2"; 
        echo "<pre>";
        print_r(DBUtil::queryAll($sql));
        echo "</pre>";
    }
}
